package com.liang.book.constant.config;

import com.liang.book.enums.ResultCodeEnum;
import com.liang.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@ResponseBody
@ControllerAdvice
//@RestControllerAdvice
public class ErrorAdvice {
    @ExceptionHandler
    public Result handler(Exception e) {
        log.error("发生异常，e:",e);
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler
    public Result handler(NullPointerException e) {
        log.error("发生NullPointerException，e:",e);
        return Result.fail("发生空指针异常："+e.getMessage());
    }
    @ExceptionHandler
    public Result handler(ArithmeticException e) {
        log.error("发生ArithmeticException，e:",e);
        return Result.fail("发生算术异常"+e.getMessage());
    }
}
